package com.feng.stateAnalysis
{
	import com.feng.ControllerCenter;
	import com.feng.debug.logger;
	import com.feng.model.Player;

	/**
	 * 攻击顺序分析
	 * @author 风之守望者
	 * 2013-4-7
	 */
	public class AttackOrderAnalysis extends AnalysisBase
	{
		/** 攻击顺序 */
		private var attackOrder:Array;

		/** 能够攻击的次数 */
		public var canAttackNum:int = 0;

		public var mySpeed:int;

		public function AttackOrderAnalysis(controllerCenter:ControllerCenter)
		{
			super(controllerCenter);
		}

		override public function analysis():void
		{

		}

		/** 计算该轮攻击顺序 */
		public function computeAttackOrder():void
		{
			attackOrder = [];
			canAttackNum = 1;
			mySpeed = me.speed;

			var playerList:Vector.<Player> = enemyList.concat();
			if (me.hp > 0)
			{
				playerList.push(me);
			}

			for each (var player:Player in playerList)
			{
				attackOrder.push({id: player.id, speed: player.speed});
			}

			attackOrder.sort(function compare(x:Object, y:Object):Number
			{
				return y.speed - x.speed;
			});

			canAttackNum = attackOrder[0].speed <= me.speed ? 2 : 1;

			logger("【计算该轮攻击顺序】");
			logger(attackOrder);
		}

		/**
		 * 找出与我同时出手的玩家
		 */
		public function getSameSpeed():Array
		{
			var playerIdList:Array = [];

			var mySpeed:int;

			var attackOrderObject:Object;
			for each (attackOrderObject in attackOrder)
			{
				if (attackOrderObject.id == me.id)
				{
					mySpeed = attackOrderObject.speed;
				}
			}

			for each (attackOrderObject in attackOrder)
			{
				if (attackOrderObject.speed == mySpeed)
				{
					playerIdList.push(attackOrderObject.id);
				}
			}

			return playerIdList;
		}
	}

}
